package com.chart.web.controller.monitor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chart.chart.domian.ChartStatistics;
import com.chart.chart.domian.req.PUReq;
import com.chart.chart.domian.req.UListReq;
import com.chart.chart.domian.req.UVipsReq;
import com.chart.chart.domian.resp.PageResp;
import com.chart.chart.domian.resp.UserResp;
import com.chart.chart.domian.vo.PUVo;
import com.chart.chart.domian.vo.StatisticsVo;
import com.chart.chart.manager.UserStatisticsManager;
import com.chart.chart.service.IChartStatisticsService;
import com.chart.common.core.controller.BaseController;
import com.chart.common.core.domain.AjaxResult;
import com.chart.common.core.domain.entity.SysUser;
import com.chart.common.utils.poi.ExcelUtil;
import com.chart.system.domain.SysUserOrder;
import com.chart.system.domain.vo.SysUserVo;
import com.chart.system.service.ISysUserOrderService;
import com.chart.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.ArrayList;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 后台数据统计
 *
 * @author chart
 */
@Api(tags = "后台数据统计模块")
@RestController
@RequestMapping("/statistics")
public class StatisticsController extends BaseController {


    @Resource
    private UserStatisticsManager userManager;



    /**
     * 获取用户数据 分页
     *
     * @param req
     * @return
     */
    @PostMapping("/list")
    public AjaxResult getListBy(@RequestBody UListReq req) {
        List<UserResp> list = userManager.getListBy(req);
        PageResp<UserResp> resp = new PageResp();
        resp.setList(list);
        resp.setTotal((long) list.size());
        return AjaxResult.success(resp);
    }

    @GetMapping("/getSource")
    public AjaxResult getSource() {
        return userManager.getSource();
    }


    @ApiOperation("导出用户数")
    @PostMapping("/exportUser")
    public void export(HttpServletResponse response, @RequestBody UListReq req) {
        List<UserResp> list = userManager.getListBy(req);
        ExcelUtil<UserResp> util = new ExcelUtil<UserResp>(UserResp.class);
        util.exportExcel(response, list, "用户数据");
    }

    @ApiOperation("获取用户PV、UV操作记录")
    @PostMapping("/getPU")
    public AjaxResult getPU(@RequestBody PUReq req) {
        List<PUVo> list = userManager.getPU(req);
        return AjaxResult.success(list);
    }


    @ApiOperation("导出用户PV、UV操作记录")
    @PostMapping("/exportPU")
    public void OpersExport(HttpServletResponse response, @RequestBody PUReq req) {
        List<PUVo> list = userManager.getPU(req);
        ExcelUtil<PUVo> util = new ExcelUtil<PUVo>(PUVo.class);
        util.exportExcel(response, list, "操作数据");
    }

    @ApiOperation("修改用户Vip信息")
    @PostMapping("/addVips")
    public AjaxResult editVips(@RequestBody UVipsReq req){
        return userManager.editVips(req);
    }


    @ApiOperation("刷新会员信息")
    @GetMapping("/updateVips")
    public AjaxResult updateVips(){
        return userManager.updateVips();
    }

}
